<template>
  <div>
    <el-form class="formcon" ref="form" :model="form" :rules="rules">
      <el-form-item label="标题:" label-width="120px" prop="infosys_title">
        <el-input v-model="form.infosys_title" placeholder="请输入标题"></el-input>
      </el-form-item>
      <el-form-item label="内容：" label-width="120px" prop="infosys_content">
        <wangeditor ref="editor" v-model="form.infosys_content"></wangeditor>
      </el-form-item>
    </el-form>
    <div class="formcon btnscon">
      <el-button type="primary" @click="save">保 存</el-button>
    </div>
  </div>
</template>

<script>
import {getInfo, addInfo} from 'api/sysParamManagementAPI'
import wangeditor from 'components/wangeditor'
import { removeTAG } from 'common/js/util'

export default {
  components: {
    wangeditor
  },
  data() {
    return {
      form: {},
      rules: {
        infosys_title: [
          { required: true, message: '请输入标题', trigger: 'change' }
        ],
        infosys_content: [
          { required: true, message: '请输入内容', trigger: 'change' },
        ]
      }
    }
  },
  methods: {
    save() {
      this.$refs.form.validate().then(()=>{
        var str = removeTAG(this.form.infosys_content)
        this.form.infosys_summary = str.substr(0, 20)
        if(this.form.infosys_summary.length === 20){
          this.form.infosys_summary += '...'
        }
        this.form.infosys_id = 2
        addInfo(this.form).then(res => {
          if(res){
            this.$message({
              message: res.rMsg,
              type: 'success'
            })
          }
        })
      })
    },
    _getInfo() {
      getInfo(2).then(res => {
        this.form = res.rData[0]
        this.$refs.editor.insertHTML(this.form.infosys_content)
      })
    }
  },
  mounted(){
    this._getInfo()
  }
}
</script>

<style lang="scss" scoped>
.formcon{
  max-width: 1000px;
}
.btnscon{
  text-align: right;
}
</style>

